package com.tuo51.evaluate.repositories.appusers;

import com.tuo51.evaluate.domain.appusers.RedeemCode;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
@CacheConfig(cacheNames = "RedeemCodeRepository")
public interface RedeemCodeRepository extends JpaRepository<RedeemCode, String>, JpaSpecificationExecutor<RedeemCode> {

    RedeemCode getByCodeAndDeletedIsFalse(String code);

    @Cacheable(keyGenerator = "keyGenerator")
    @Query(value = "select * from redeem_code where code = :code and deleted = false", nativeQuery = true)
    RedeemCode previewCode(@Param("code")  String code);

}
